<?php

namespace App\Traits\Relation;

use App\Models\Inspection\Line;
use App\Models\User;
use App\Models\Genre;
use App\Models\Project;
use App\Models\Attendance;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

trait ScheduleRelation
{
    /**
     * 获取排班对应的考勤记录
     *
     * Date: 22/04/2018
     * @author George
     * @return mixed
     */
    public function attendance()
    {
        return $this->hasOne(Attendance::class, 'schedule_id', 'id');
    }

	/**
	 * 获取排班关联的班次
	 *
	 * Date: 2018/6/19
	 * @author George
	 * @return mixed
	 */
	public function genre()
	{
		return $this->hasOne(Genre::class, 'id', 'genre_id');
    }

    /**
     * 获取排班记录的班次类型
     *
     * Date: 23/04/2018
     * @author George
     * @return BelongsToMany
     */
    public function genres()
    {
        return $this->belongsToMany(Genre::class, 'schedule_genre_pivot', 'schedule_id', 'genre_id', 'id', 'id');
    }

	/**
	 * 获取排班关联的项目
	 *
	 * Date: 28/04/2018
	 * @author George
	 * @return BelongsTo
	 */
	public function project()
	{
		return $this->belongsTo(Project::class, 'project_id', 'id');
    }

	/**
	 * 获取用户信息
	 *
	 * Date: 02/05/2018
	 * @author George
	 * @return BelongsTo
	 */
	public function user()
	{
		return $this->belongsTo(User::class, 'user_id', 'id');
    }

	/**
	 * 获取排班指定的线路
	 *
	 * Date: 06/05/2018
	 * @author George
	 * @return BelongsTo
	 */
	public function line()
	{
		return $this->belongsTo(Line::class, 'line_id', 'id');
    }
}
